<!-- ParentComponent.vue -->
<template>
  <ChildComponent ref="childRef" />
  <button @click="callChildMethod">调用子组件方法</button>
</template>

<script>
import { ref } from 'vue'
import ChildComponent from './ChildComponent.vue'

export default {
  components: { ChildComponent },
  setup() {
    const childRef = ref(null)

    const callChildMethod = () => {
      if (childRef.value) {
        childRef.value.childMethod('parent-child')
      }
    }

    return {
      childRef,
      callChildMethod
    }
  }
}
</script>
